package team.szm.scd.controller;

import org.springframework.web.bind.annotation.*;
import team.szm.scd.database.dto.RequestWrapper;
import team.szm.scd.database.dto.Result;
import team.szm.scd.database.entity.Medicine;
import team.szm.scd.service.interfaces.ILoginService;
import team.szm.scd.service.interfaces.IMedicineService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/medicine")
public class MedicineController {

    @Resource
    IMedicineService service;
    @Resource
    ILoginService loginService;

    @PostMapping("/search")
    @ResponseBody
    public Result<List<Medicine>> searchMedicine(
            @RequestBody RequestWrapper<String> name, HttpSession session) {
        if (loginService.noDoctorLogin(session)) {
            return Result.needLogin();
        }
        return Result.success(service.searchMedicine(name.value));
    }
}
